package com.ysx.ch03;

import org.junit.Test;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;


public class Client {


    @Test
    public  void add(){
        AnnotationConfigApplicationContext context
                = new AnnotationConfigApplicationContext(ScottConfiguration.class);

        // 一般人很难看懂
        Cal cal = getCal(context);
        cal.add();

    }


    public Cal getCal(AnnotationConfigApplicationContext context){
        ProxyFactoryBean bean= new ProxyFactoryBean();
        bean.setBeanFactory(context);

        //把我们的方法和通知绑定
        bean.setInterceptorNames("successAdvice");
        bean.setTarget(context.getBean(Cal.class));

        context.getBeanFactory().registerSingleton("scott",bean);
        Cal cal = (Cal)context.getBean("scott");
        return cal;
    }
}
